package com.fingard.dsp.bank.directbank.cbs01;

import java.sql.Connection;
import java.sql.Statement;

import com.fingard.db.ConnSet;
import com.fingard.dsp.bank.directbank.DirectBase;



public class CBS01Base extends DirectBase {
	
	public Connection getConnection() throws Exception{
		ConnSet connSet = bankFront.getConnSet("*");
		Connection conn=connSet.getConnection();
	    //Class.forName(bankFront.dbDriver);
		//conn=DriverManager.getConnection(bankFront.dbUrl,bankFront.dbUser,bankFront.dbPassword);
		return conn;
	}
	
	public int executeNonQrySql(String p_sql) throws Exception {
		int retValue = -1;
	    Statement st =null;
	    ConnSet connSet = bankFront.getConnSet("*");
	    Connection conn=connSet.getConnection();
	    //Class.forName(bankFront.dbDriver);
		//conn=DriverManager.getConnection(bankFront.dbUrl,bankFront.dbUser,bankFront.dbPassword);
		try{
			conn.setAutoCommit(false);    
			st =conn.createStatement();
			retValue = st.executeUpdate(p_sql);
			conn.commit();
		}
		catch(Exception ex ){
			conn.rollback(); 
			throw new Exception(ex);
		}
		finally{
			if(st!=null){
				st.close();
			}
			if(conn!=null){
			    conn.close();
			}
		}
		return retValue;
	}
	
	protected String getCHECK_CODE(String...p_values){
		int s = 0;
		for(int i=0; i<p_values.length; i++){
			if(p_values[i] != null && p_values[i].length() > 0){
				for(int j=0;j<p_values[i].length();j++){
					s = s + p_values[i].charAt(j);
				}
			}
			s = s+ 39;
		}
		s = ((s % 999) * (s % 2184)) % 9999;
		return String.valueOf(s);
	}
}
